import cv2
import numpy as np
import matplotlib.pyplot as plt

from skimage import measure
import visionAndTouch.utils as utils

observedImage = cv2.imread('testingImages/temp2.png')
encodedImageT = utils.encodeImageTorch(observedImage)
encodedImage = encodedImageT.cpu().numpy()
label = measure.label(encodedImage, connectivity=2)
props = measure.regionprops(label)
for p in props:
    print(p.area)
# Find contours at a constant value of 0.8
regImage = np.squeeze(props[0].image, axis=2)
contours = measure.find_contours(regImage, 0.8)

# Display the image and plot all contours found
fig, ax = plt.subplots()
ax.imshow(regImage, cmap=plt.cm.gray)

# for contour in contours:
#     ax.plot(contour[:, 1], contour[:, 0], linewidth=2)

ax.axis('image')
ax.set_xticks([])
ax.set_yticks([])
plt.show()